package com.shengruan.admin.action;

import org.apache.commons.configuration.PropertiesConfiguration;

import com.shengruan.common.BaseAction;
import com.shengruan.common.Constants;

public class SystemSettingsAction extends BaseAction {


    public void load() throws Exception {
        PropertiesConfiguration config = new PropertiesConfiguration("auction.properties");
        String userInviteMaxBidding = config.getString("user.InviteMaxBidding");
        String productDisableDays = config.getString("product.disable.days");

        this.setRequest("userInviteMaxBidding", userInviteMaxBidding);
        this.setRequest("productDisableDays", productDisableDays);
        this.forward("/admin/system/system-settings.jsp");
    }

    public void edit() throws Exception {

        String userInviteMaxBidding = this.input("userInviteMaxBidding");
        String productDisableDays = this.input("productDisableDays");

        PropertiesConfiguration config = new PropertiesConfiguration("auction.properties");
        config.setProperty("user.InviteMaxBidding", userInviteMaxBidding);
        config.setProperty("product.disable.days", productDisableDays);

        config.save();

        Constants.USER_INVITEMAXBIDDING = Integer.valueOf(userInviteMaxBidding);
        Constants.PRODUCT_DISABLE_DAYS = Integer.valueOf(productDisableDays);


        this.redirect("/admin/system/system-settings-load.ac");
    }
}
